package com.demo.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo.dao.BaogaoInfoMapper;
import com.demo.dao.KeShiBiaoMapper;
import com.demo.dao.YiShengMapper;
import com.demo.dao.YiShengPaiBanMapper;
import com.demo.dao.YuYueJiuZhengMapper;
import com.demo.entity.BaogaoInfo;
import com.demo.entity.User;
import com.demo.entity.YiSheng;
import com.demo.entity.YiShengPaiBan;
import com.demo.entity.YuYueJiuZheng;

@Service
public class BaoGaoInfoService{
	@Autowired
	private BaogaoInfoMapper baogaoInfoMapper;
	
	@Autowired
	private YiShengMapper yiShengMapper;
	
	@Autowired
	private KeShiBiaoMapper keShiBiaoMapper;
	
	@Autowired
	private YuYueJiuZhengMapper yuYueJiuZhengMapper;
	
	public int deleteByPrimaryKey(Integer id) {
		return baogaoInfoMapper.deleteByPrimaryKey(id);
	}

	public int insert(BaogaoInfo record){
		return baogaoInfoMapper.insert(record);
	}

	public List<BaogaoInfo> selectAll(){
		List<BaogaoInfo> liste = new ArrayList<BaogaoInfo>();
		List<BaogaoInfo> list = baogaoInfoMapper.selectAll();
		if(list.size()>0) {
			for (int i = 0; i < list.size(); i++) {
				BaogaoInfo nBaogaoInfo = list.get(i);
				String id = nBaogaoInfo.getYyuejiuzhengid();
				if(id!=""&&id!=null&&id!="null") {
					YuYueJiuZheng yuYueJiuZheng = yuYueJiuZhengMapper.selectByPrimaryKey(Integer.valueOf(id));
					if(yuYueJiuZheng!=null) {
						YuYueJiuZheng yuYueJiuZheng2 = yuYueJiuZheng;
						int yishengid = (yuYueJiuZheng.getYisheng()!=""&&yuYueJiuZheng.getYisheng()!=null)?Integer.valueOf(yuYueJiuZheng.getYisheng()):0;
						if(yishengid!=0) {
							YiSheng yiSheng = yiShengMapper.selectByPrimaryKey(yishengid);
							if(yiSheng!=null) {
								yuYueJiuZheng2.setDoctorName(yiSheng.getName());
								yuYueJiuZheng2.setKeshiName(keShiBiaoMapper.selectByPrimaryKey(
										Integer.valueOf(yiSheng.getKeshi())).getKeshi());
							}
						}
						nBaogaoInfo.setYuyue(yuYueJiuZheng2);
					}
				}
				
				liste.add(nBaogaoInfo);
			}
		}
		return liste;
	}

	public List<BaogaoInfo> selectByid(String i1d){
		List<BaogaoInfo> liste = new ArrayList<BaogaoInfo>();
		List<BaogaoInfo> list = baogaoInfoMapper.selectByid(i1d);
		if(list.size()>0) {
			for (int i = 0; i < list.size(); i++) {
				BaogaoInfo nBaogaoInfo = list.get(i);
				String id = nBaogaoInfo.getYyuejiuzhengid();
				if(id!=""&&id!=null&&id!="null") {
					YuYueJiuZheng yuYueJiuZheng = yuYueJiuZhengMapper.selectByPrimaryKey(Integer.valueOf(id));
					if(yuYueJiuZheng!=null) {
						YuYueJiuZheng yuYueJiuZheng2 = yuYueJiuZheng;
						int yishengid = (yuYueJiuZheng.getYisheng()!=""&&yuYueJiuZheng.getYisheng()!=null)?Integer.valueOf(yuYueJiuZheng.getYisheng()):0;
						if(yishengid!=0) {
							YiSheng yiSheng = yiShengMapper.selectByPrimaryKey(yishengid);
							if(yiSheng!=null) {
								yuYueJiuZheng2.setDoctorName(yiSheng.getName());
								yuYueJiuZheng2.setKeshiName(keShiBiaoMapper.selectByPrimaryKey(
										Integer.valueOf(yiSheng.getKeshi())).getKeshi());
							}
						}
						nBaogaoInfo.setYuyue(yuYueJiuZheng2);
					}
				}
				
				liste.add(nBaogaoInfo);
			}
		}
		return liste;
	}
	public int updateByPrimaryKey(BaogaoInfo record){
		return baogaoInfoMapper.updateByPrimaryKey(record);
	}
	
	
	/**
	 * for (YuYueJiuZheng yuYueJiuZheng : list) {
				YuYueJiuZheng yuYueJiuZheng2 = yuYueJiuZheng;
				System.out.println(yuYueJiuZheng2.toString());
				int yishengid = (yuYueJiuZheng.getYisheng()!=""&&yuYueJiuZheng.getYisheng()!=null)?Integer.valueOf(yuYueJiuZheng.getYisheng()):0;
				if(yishengid!=0) {
					YiSheng yiSheng = yiShengMapper.selectByPrimaryKey(yishengid);
					if(yiSheng!=null) {
						yuYueJiuZheng2.setDoctorName(yiSheng.getName());
						yuYueJiuZheng2.setKeshiName(keShiBiaoMapper.selectByPrimaryKey(
								Integer.valueOf(yiSheng.getKeshi())).getKeshi());
					}
				}
				if(yonghu!=""&&yonghu!="null"&&yonghu!=null) {
					User user = userMapper.selectByPrimaryKey(Integer.valueOf(yonghu));
					yuYueJiuZheng2.setYonghuName(user.getName());
				}
				listre.add(yuYueJiuZheng2);
			}
	 */
  
	
}
